//
//  CommentsViewCommentCell.swift
//  
//
//  Created by Ralf on 15/6/14.
//
//

import UIKit

class CommentsViewCommentCell: UITableViewCell
{
    let __text_view_tag = 100

    var textView: UITextView!
    override func awakeFromNib()
    {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(selected: Bool, animated: Bool)
    {
        super.setSelected(selected, animated: animated)
        // Configure the view for the selected state
    }

    func setData(data: [String:AnyObject])
    {
        initTextView()

        let paragraphStyle = NSMutableParagraphStyle()

        paragraphStyle.lineHeightMultiple = 16
        paragraphStyle.maximumLineHeight = 16
        paragraphStyle.minimumLineHeight = 16

        paragraphStyle.alignment = .Left

        let attributes = [NSFontAttributeName: UIFont.systemFontOfSize(12),
                          NSParagraphStyleAttributeName: paragraphStyle,
                          NSForegroundColorAttributeName: UIColor.darkGrayColor()]
        let textView   = self.viewWithTag(__text_view_tag) as! UITextView
        textView.attributedText = NSAttributedString(string: data["message"] as! String, attributes: attributes)
    }

    func initTextView()
    {
        var textView = self.viewWithTag(__text_view_tag) as? UITextView

        if textView == nil
        {
            textView = UITextView()
            self.addSubview(textView!)
        }

        let frame = CGRect(x: 45, y: 0.0, width: self.bounds.size.width - 50, height: self.bounds.size.height)
        textView!.frame = frame
        textView!.scrollEnabled = false
        textView!.selectable = false
        textView!.tag = __text_view_tag
        textView!.editable = false
    }
}
